/**
 * Created with IntelliJ IDEA.
 * User: tranmanhcuong
 * Date: 9/10/13
 * Time: 12:02 PM
 * To change this template use File | Settings | File Templates.
 */
package PlaneAkka

import akka.actor.{Props, Actor, ActorLogging}
import PlaneAkka.EventSource._

object Plane {
  case object GiveMeControl
}

class Plane extends Actor with ActorLogging {
  import Altimeter._
  import Plane._
  val altimeter = context.actorOf(Props[Altimeter])
  val controls = context.actorOf(Props(new ControlSurfaces(altimeter)))
  def receive = {
    case GiveMeControl =>
      log.info("Plane giving control.")
      sender ! controls

    case AltitudeUpdate(altitude) =>
      log.info(s"Altitude is now: $altitude")
  }

  override def preStart() {
    altimeter ! RegisterListener(self)
  }
}